package Day05;

import java.util.Iterator;
import java.util.Stack;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-09-13
 * Time: 12:06
 * To BE A Better Person-2020-3-2
 */
class MyStack<E> extends Stack{
    @Override
    public String toString() {
        Iterator<E> it = iterator();
        if (! it.hasNext())
            return "";

        StringBuilder sb = new StringBuilder();
        for (;;) {
            E e = it.next();
            sb.append(e == this ? "(this Collection)" : e);
            if (! it.hasNext())
                return sb.toString();
            sb.append(',').append(' ');
        }
    }
}
public class TestDemo2 {

    public static String replaceSpace (String s) {
        // write code here
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<s.length();i++){
            if(s.charAt(i) != ' '){
                stack.push(s.charAt(i));
            }else{
                stack.push('%');
                stack.push('2');
                stack.push('0');
            }
        }

        return stack.toString();
    }

    public static void main(String[] args) {
        String s="hhh hhh hhh  ";
        String ret=replaceSpace(s);
        System.out.println(s);
    }
}
